1 /* 2 * Hunt - a framework for web and console application based on Collie using Dlang development 3 * 4 * Copyright (C) 2015-2017 Shanghai Putao Technology Co., Ltd 5 * 6 * Developer: HuntLabs 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module hunt.routing.route; 13 14 import hunt.routing.define; 15 16 class Route 17 { 18 this() 19 { 20 // Constructor code 21 } 22 23 public 24 { 25 Route copy() 26 { 27 Route route = new Route; 28 29 route.setGroup(_group) 30 .setUrlTemplate(_urlTemplate) 31 .setRoute(_route) 32 .setParamKeys(_paramKeys) 33 .setPattern(_pattern) 34 .setRegular(_regular) 35 .setModule(_module) 36 .setController(_controller) 37 .setAction(_action) 38 .setMethods(_methods) 39 .handle(_handle); 40 41 return route; 42 } 43 44 Route setGroup(string groupValue) 45 { 46 this._group = groupValue; 47 return this; 48 } 49 50 string getGroup() 51 { 52 return this._group; 53 } 54 55 Route setUrlTemplate(string urlTemplate) 56 { 57 this._urlTemplate = urlTemplate; 58 return this; 59 } 60 61 string getUrlTemplate() 62 { 63 return this._urlTemplate; 64 } 65 66 Route setRoute(string routeValue) 67 { 68 this._route = routeValue; 69 return this; 70 } 71 72 string getRoute() 73 { 74 return this._route; 75 } 76 77 Route setParamKeys(string[int] paramKeys) 78 { 79 this._paramKeys = paramKeys; 80 return this; 81 } 82 83 string[int] getParamKeys() 84 { 85 return this._paramKeys; 86 } 87 88 Route setParams(string[string] params) 89 { 90 this._params = params; 91 return this; 92 } 93 94 string[string] getParams() 95 { 96 return this._params; 97 } 98 99 Route setPattern(string patternValue) 100 { 101 this._pattern = patternValue; 102 return this; 103 } 104 105 string getPattern() 106 { 107 return this._pattern; 108 } 109 110 Route setRegular(bool regularValue) 111 { 112 this._regular = regularValue; 113 return this; 114 } 115 116 bool getRegular() 117 { 118 return this._regular; 119 } 120 121 Route setModule(string moduleValue) 122 { 123 this._module = moduleValue; 124 return this; 125 } 126 127 string getModule() 128 { 129 return this._module; 130 } 131 132 Route setController(string controllerValue) 133 { 134 this._controller = controllerValue; 135 return this; 136 } 137 138 string getController() 139 { 140 return this._controller; 141 } 142 143 Route setAction(string actionValue) 144 { 145 this._action = actionValue; 146 return this; 147 } 148 149 string getAction() 150 { 151 return this._action; 152 } 153 154 Route setMethods(HTTP_METHODS[] methods) 155 { 156 this._methods = methods; 157 return this; 158 } 159 160 HTTP_METHODS[] getMethods() 161 { 162 return this._methods; 163 } 164 165 @property handle() 166 { 167 return this._handle; 168 } 169 170 @property Route handle(HandleFunction handle) 171 { 172 this._handle = handle; 173 return this; 174 } 175 176 @property staticFilePath() 177 { 178 return this._staticFilePath; 179 } 180 181 @property void staticFilePath(string path) 182 { 183 this._staticFilePath = path; 184 } 185 } 186 187 public string path; 188 private 189 { 190 // Route group name 191 string _group; 192 193 // Regex template 194 string _urlTemplate; 195 196 // http uri params 197 string[int] _paramKeys; 198 199 string[string] _params; 200 201 // like uri path 202 string _pattern; 203 204 // path to module.controller.action 205 string _route; 206 207 // use regex? 208 bool _regular; 209 210 // hunt module 211 string _module; 212 213 // hunt controller 214 string _controller; 215 216 // hunt action 217 string _action; 218 219 // handle function 220 HandleFunction _handle; 221 222 // allowd http methods 223 HTTP_METHODS[] _methods = [ HTTP_METHODS.GET, HTTP_METHODS.POST, HTTP_METHODS.PUT, HTTP_METHODS.DELETE ]; 224 225 // staticDir:path 226 string _staticFilePath; 227 } 228 }